﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LIMS.Web
{
    public partial class AdminStuAdd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                bindGradeNos();
            }
        }

        /// <summary>
        /// 绑定班级名称、班级ID
        /// </summary>
        private void bindGradeNos()
        {
            rbClassList.Items.Clear();
            var gradeDict = BLL.StudentManager.GetClassIDAndNo();
            foreach (KeyValuePair<Int32, String> item in gradeDict)
            {
                rbClassList.Items.Add(new ListItem(item.Value, item.Key.ToString()));
            }
            rbClassList.DataBind();
            rbClassList.SelectedIndex = 0;
        }


        protected void btnOK_Click(object sender, EventArgs e)
        {
            Model.Students stu = new Model.Students()
            {
                stuNo = txtStudentID.Text.Trim(),
                stuName = txtStudentName.Text.Trim(),
                stuGender = selGender.Value == "1" ? "男" : "女",
                stuPwd = txtPassword1.Text.Trim(),
                classID = Int32.Parse(rbClassList.SelectedItem.Value)
            };
            BLL.StudentManager.AddStudent(stu);
            Response.Redirect("AdmStuManage.aspx");
        }

    }
}